import { IDispose } from "../Interfaces/IDispose";

export class FBinder implements IDispose
{
    protected asset:cc.Node;
    protected disObjects:IDispose[] = [];
    public bindView(asset:cc.Node,...args):void
    {
        if(this.asset!=null)
            this.clearViews();
        this.asset = asset;
        this.initViews();
    }
    protected initViews():void
    {
    }
    protected clearViews():void
    {
    }
    public update(...datas):void
    {
    }
    public dispose():void
    {
        this.clearViews();
        this.disposeObjects();
        this.asset = null;
    }
    protected addObject(obj:IDispose):void
    {
        if(this.disObjects.indexOf(obj)==-1)
            this.disObjects.push(obj);
    }
    protected disposeObjects():void
    {
        while(this.disObjects.length>0)
        {
            this.disObjects.shift().dispose();
        }
    }
}
